//
//  DHReceptionRequirementViewController.m
//  DHKuaiYi
//
//  Created by  chenhanmao on 2016/11/16.
//  Copyright © 2016年 30-陈辉华. All rights reserved.
//

#import "DHReceptionRequirementViewController.h"
#import "NetworkTool.h"
#import <Masonry.h>

@interface DHReceptionRequirementViewController ()

/**  接诊条件  */
@property(nonatomic,weak) UILabel *receptionRequirementLabel;

/**  条件1  */
@property(nonatomic,weak) UILabel *requireLabel1;
/**  条件2  */
@property(nonatomic,weak) UILabel *requireLabel2;
/**  条件3  */
@property(nonatomic,weak) UILabel *requireLabel3;
/**  条件4  */
@property(nonatomic,weak) UILabel *requireLabel4;
/**  条件5  */
@property(nonatomic,weak) UILabel *requireLabel5;

@end

@implementation DHReceptionRequirementViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self requestWithParameters:@{@"doctor_id":@300000315}];
}

- (void)xhhSetupSubviews {
    
    UILabel *receptionRequirementLabel = [[UILabel alloc] init];
    
    self.receptionRequirementLabel = receptionRequirementLabel;
    
    receptionRequirementLabel.numberOfLines = 0;
    
    [self.view addSubview:receptionRequirementLabel];
    
    
    UILabel *requireLabel1 = [[UILabel alloc] init];
    self.requireLabel1 = requireLabel1;
    requireLabel1.text = @"just test";
    [self.view addSubview:requireLabel1];
    
    UILabel *requireLabel2 = [[UILabel alloc] init];
    self.requireLabel2 = requireLabel2;
    [self.view addSubview:requireLabel2];
    
    UILabel *requireLabel3 = [[UILabel alloc] init];
    self.requireLabel3 = requireLabel3;
    [self.view addSubview:requireLabel3];
    
    UILabel *requireLabel4 = [[UILabel alloc] init];
    self.requireLabel4 = requireLabel4;
    [self.view addSubview:requireLabel4];
    
    UILabel *requireLabel5 = [[UILabel alloc] init];
    self.requireLabel5 = requireLabel5;
    [self.view addSubview:requireLabel5];
    
   /*------------------自动布局------------------*/
    
    CGFloat space = 16;
    [receptionRequirementLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.top.equalTo(self.view).offset(space);
        make.right.equalTo(self.view).offset(-space);
    }];
    
    [requireLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.top.equalTo(receptionRequirementLabel.mas_bottom).offset(space);
    }];
    
    [requireLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.top.equalTo(requireLabel1.mas_bottom).offset(space);
    }];
    
    [requireLabel3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.top.equalTo(requireLabel2.mas_bottom).offset(space);
    }];
    
    [requireLabel4 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.top.equalTo(requireLabel3.mas_bottom).offset(space);
    }];
    
    [requireLabel5 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.top.equalTo(requireLabel4.mas_bottom).offset(space);
    }];
}

/**
 网络请求
 */
-(void)requestWithParameters:(NSDictionary *)parameters {
    
    NSString *URLString = @"http://iosapi.itcast.cn/doctor/doctorReceivingSetting.json.php";
    //    @{@"doctor_id":@300000315}
    
    [[NetworkTool sharedTool] POSTWithURLStr:URLString parameters:parameters success:^(id responseObject) {
        if (responseObject != nil) {
            
            NSString *receptionRequirement = responseObject[@"data"][@"receiving_setting_extra"];
            
            NSArray *receiving_settings = responseObject[@"data"][@"receiving_settings"];
            
            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                
                self.receptionRequirementLabel.text = receptionRequirement;
                [self.receptionRequirementLabel sizeToFit];
                
                self.requireLabel1.text = receiving_settings[0];
                self.requireLabel2.text = receiving_settings[1];
                self.requireLabel3.text = receiving_settings[2];
                self.requireLabel4.text = receiving_settings[3];
                self.requireLabel5.text = receiving_settings[4];
            }];
        }
    } failed:^(NSError *error) {
        
        NSLog(@"%@",error);
        
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
